package com.ctg.itrdc.imageconsole.data.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.ctg.itrdc.imageconsole.data.dao.IDockerMicroGroupDetailDao;
import com.ctg.itrdc.imageconsole.data.entity.DockerMicroGroupDetail;
import com.ctg.itrdc.paspsdk.data.dao.impl.BaseDaoImpl;

@Component("dockerMicroGroupDetailDao")
public class DockerMicroGroupDetailDaoImpl extends BaseDaoImpl implements IDockerMicroGroupDetailDao{

	@Override
	public Long insert(Long groupId, String nodeName) 
	{
		DockerMicroGroupDetail groupDetail = new DockerMicroGroupDetail();
		groupDetail.setDockerMicroGroupId(groupId);
		groupDetail.setNodeName(nodeName);
		return super.insert(groupDetail);
	}

	@Override
	public List<DockerMicroGroupDetail> selectByDockerMicroGroupId(Long dockerMicroGroupId) 
	{
		DockerMicroGroupDetail GroupDetail = new DockerMicroGroupDetail();
		GroupDetail.setDockerMicroGroupId(dockerMicroGroupId);
		return super.selectByExample(GroupDetail);
	}

	@Override
	public void deleteByDockerMicroGroupId(Long dockerMicroGroupId) 
	{
		DockerMicroGroupDetail GroupDetail = new DockerMicroGroupDetail();
		GroupDetail.setDockerMicroGroupId(dockerMicroGroupId);
		List<DockerMicroGroupDetail> GroupDetailList = super.selectByExample(GroupDetail);
		super.jdbcBatchDeleteByPrimary(GroupDetailList);
	}

	@Override
	public void deleteByDockerMicroGroupIdAndNodeName(Long dockerMicroGroupId, String nodeName) 
	{
		DockerMicroGroupDetail GroupDetail = this.selectByDockerMicroGroupIdAndNodeName(dockerMicroGroupId, nodeName);		
		super.deleteByPrimaryKey(GroupDetail);
		
	}

	@Override
	public DockerMicroGroupDetail selectByDockerMicroGroupIdAndNodeName(Long dockerMicroGroupId, String nodeName) 
	{
		DockerMicroGroupDetail GroupDetail = new DockerMicroGroupDetail();
		GroupDetail.setDockerMicroGroupId(dockerMicroGroupId);
		GroupDetail.setNodeName(nodeName);
		List<DockerMicroGroupDetail> GroupDetailList = super.selectByExample(GroupDetail);
		if(GroupDetailList.size() > 1)
			throw new RuntimeException("Error : selecting docker_micro_Group_detail returns " + GroupDetailList.size() + " records, 0 or 1 desired");
		return GroupDetailList.isEmpty() ? null : GroupDetailList.get(0);
	}

	
	
	
}
